use slab::Slab;

pub struct Arena<T>{
    slab: Slab<T>
}

impl <T>Arena<T> {
    pub(crate) fn new()->Self {
        Self {
            slab: Slab::default()
        }
    }
    pub(crate) fn alloc(&mut self, value: T) -> usize {
        self.slab.insert(value)
    }

    pub(crate) fn dealloc(&mut self, ptr: usize) {
        self.slab.remove(ptr);
    }

    pub(crate) fn deref(&self, ptr: usize) -> &T {
        &self.slab[ptr]
    }

    pub(crate) fn deref_mut(&mut self, ptr: usize) -> &mut T {
        &mut self.slab[ptr]
    }
}
